package com.ruoyi.stock.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.stock.domain.StockDaily;
import com.ruoyi.stock.service.IStockDailyService;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 股票K线数据信息Controller
 *
 * @author ruoyi
 * @date 2021-10-22
 */
@RestController
@RequestMapping("/stock/kData")
public class StockKDataController extends BaseController {
  @Autowired private IStockDailyService stockDailyService;

  /** 查询股票基本信息列表 */
  @PreAuthorize("@ss.hasPermi('stock:kData:list')")
  @GetMapping("/list")
  public List list(String stockCode) {
    List<StockDaily> stockDailies =
        stockDailyService.selectStockDailyList(StockDaily.builder().symbol(stockCode).build());
    Collections.reverse(stockDailies);
    return stockDailies.stream()
        .map(
            model ->
                Arrays.asList(
                    model.getTradeDate(),
                    model.getOpen(),
                    model.getClose(),
                    model.getLow(),
                    model.getHigh(),
                    model.getVol().divide(new BigDecimal(10), BigDecimal.ROUND_HALF_UP)))
        .collect(Collectors.toList());
  }
}
